import type { PluginOption } from "vite";
import { isDevelopment, isProduction } from "./util";
import legacy from "@vitejs/plugin-legacy";
import packageInfo from "../package.json";

export function buildVitePlugin() {
  const vitePluginArr: (PluginOption | PluginOption[])[] = [];

  if (isProduction) {
    // 加入仅生产时需要的插件
    vitePluginArr.push(
      legacy({
        targets: packageInfo.browserslist, //需要兼容的浏览器以及对应版本，统一配置在了package.json的browserslist
        additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
      })
    );
  } else if (isDevelopment) {
    // 加入仅开发时需要的插件
  }
  return vitePluginArr;
}
